﻿<%@ Page Title="" Language="C#" MasterPageFile="~/layout/layout.Master" AutoEventWireup="true" CodeBehind="Cart.aspx.cs" Inherits="SinhNhat.Cart" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentHead" runat="server">
    <title>Giỏ hàng</title>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="content_home" runat="server">
    <asp:ScriptManager ID="scriptmanager" runat="server" />

    <script type="text/javascript">

        function changePayment(ddl) {
            if (ddl.value.toUpperCase() == "81461F5F-D54D-4C49-83F5-72821161998A") {
                document.getElementById("bank1").style.visibility = "visible";
                document.getElementById("bank2").style.visibility = "visible";
            }
            else {
                document.getElementById("bank1").style.visibility = "hidden";
                document.getElementById("bank2").style.visibility = "hidden";
            }

        }

        function Valid() {
            var valid = true;

            var errorStr = "";

            var txtName = document.getElementById("<%=txtName.ClientID %>");
            var txtPhone = document.getElementById("<%=txtPhone.ClientID %>");

            if (txtName.value == '') {
                txtName.setAttribute('class', 'textbox textinfo textValid');
                errorStr += "<li style='color:red;'>Nhập họ tên</li>";
                txtName.focus();
                valid = false;
            }
            else {
                txtName.setAttribute('class', 'textbox textinfo');
            }

            if (txtPhone.value == '') {
                txtPhone.setAttribute('class', 'textbox textinfo textValid');
                errorStr += "<li style='color:red;'>Nhập số điện thoại</li>";
                txtPhone.focus();
                valid = false;
            }
            else {
                txtPhone.setAttribute('class', 'textbox textinfo');
            }

            if (valid == false) {
                errorStr = "<ul>" + errorStr + "</ul>";
                document.getElementById("divError").innerHTML = errorStr;
            }
            else {
                document.getElementById("divError").innerHTML = "";

                if (confirm('Đơn đặt hàng sẽ được gửi đi') == false) {
                    return false;
                }
                else {
                    document.getElementById("divError").innerHTML = "Đang gửi đơn đặt hàng. Vui lòng chờ...";
                }
            }

            return valid;
        }
    </script>

    <div id="main">
        <asp:UpdatePanel ID="up" runat="server" UpdateMode="Conditional">
            <ContentTemplate>

                <div id="cartDiv" runat="server">
                    <div>
                        <h2 style="float:left">Các sản phẩm đã chọn</h2>
                        <h2 style="float:right">
                            
                            <table>
                                <tr>
                                    <td>
                                        <img src="/data/images/back.png" width="20px" />
                                    </td>
                                    <td>
                                        <a href="/Index.aspx" title="Tiếp tục mua hàng" >Tiếp tục mua hàng</a>
                                    </td>
                                </tr>
                            </table>
                        </h2>

                        <div class="clearfix"></div>
                    </div>
        
                    <asp:GridView ID="grCart" runat="server" AutoGenerateColumns="False" 
                        CellPadding="4" ForeColor="#333333" GridLines="None">
                        <AlternatingRowStyle BackColor="White" />
                        <Columns>
                            <asp:TemplateField HeaderText="STT" ItemStyle-Width="30px" ItemStyle-HorizontalAlign="Center">
                                <ItemTemplate>
                                    <%# Container.DataItemIndex + 1 %>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="Tên sản phẩm" ItemStyle-Width="230px">
                                <ItemTemplate>
                                    <table>
                                        <tr>
                                            <td>
                                                <a href='<%# Eval("Product.Url")%>' target="_blank" title='<%# Eval("Product.Name")%>'>
                                                    <img src='<%# Eval("Product.Image")%>' width="60px" />        
                                                </a>
                                            </td>
                                            <td>
                                                <a href='<%# Eval("Product.Url")%>' target="_blank" title='<%# Eval("Product.Name")%>'>
                                                    <%# Eval("Product.Name")%>
                                                </a>
                                            </td>
                                        </tr>
                                    </table>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="Đơn giá" ItemStyle-Width="130px" ItemStyle-HorizontalAlign="Center">
                                <ItemTemplate>
                                    <%# string.Format("{0:N0} VNĐ", Eval("Product.Price"))%> 
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="Số lượng đặt" ItemStyle-Width="100px" ItemStyle-HorizontalAlign="Center">
                                <ItemTemplate>
                                    <table>
                                        <tr>
                                            <td>
                                                <asp:TextBox ID="txtQuantity" runat="server" Text='<%# Eval("Quantity") %>' 
                                                    ReadOnly="true" CssClass="textbox quantity" />
                                            </td>
                                            <td>
                                                <div>
                                                    <asp:ImageButton ID="btnUp" runat="server" ImageUrl="/data/images/quantity_up.png" 
                                                    ToolTip="Tăng" CommandArgument="Up" CommandName='<%# Eval("Product.ProductID")%>' />
                                                </div>
                                                <div>
                                                    <asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="/data/images/quantity_down.png" 
                                                    ToolTip="Giảm" CommandArgument="Down" CommandName='<%# Eval("Product.ProductID")%>' />
                                                </div>
                                            </td>
                                        </tr>
                                    </table>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="Tuỳ chọn" ItemStyle-Width="60px" ItemStyle-HorizontalAlign="Center">
                                <ItemTemplate>
                                    <asp:Button ID="btnDel" runat="server" Text="Xoá" ToolTip="Xoá sản phẩm" CssClass="button"
                                    CommandArgument="Del" CommandName='<%# Eval("Product.ProductID")%>' />
                                </ItemTemplate>
                            </asp:TemplateField>
                        </Columns>
                        <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
                        <HeaderStyle BackColor="#990000" Font-Bold="True" Font-Size="Small" ForeColor="White" />
                        <PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
                        <RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
                        <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
                        <SortedAscendingCellStyle BackColor="#FDF5AC" />
                        <SortedAscendingHeaderStyle BackColor="#4D0000" />
                        <SortedDescendingCellStyle BackColor="#FCF6C0" />
                        <SortedDescendingHeaderStyle BackColor="#820000" />
                    </asp:GridView>

                    <div style="text-align:right;">
                        Tổng cộng: <asp:Label ID="lblSum" runat="server" />
                    </div>
        
                    <h2>Thông tin khách hàng</h2>

                    <table>
                        <tr>
                            <td style="width:150px">Họ tên:</td>
                            <td>
                                <asp:TextBox ID="txtName" runat="server" CssClass="textbox textinfo" />
                            </td>
                        </tr>
                        <tr>
                            <td>Điện thoại:</td>
                            <td>
                                <asp:TextBox ID="txtPhone" runat="server" CssClass="textbox textinfo" />
                            </td>
                        </tr>
                        <tr>
                            <td>Email:</td>
                            <td>
                                <asp:TextBox ID="txtEmail" runat="server" CssClass="textbox textinfo" />
                            </td>
                        </tr>
                        <tr>
                            <td>Địa chỉ:</td>
                            <td>
                                <asp:TextBox ID="txtAddress" runat="server" TextMode="MultiLine" Rows="4" CssClass="textbox textinfo textover" />
                            </td>
                        </tr>
                        <tr>
                            <td>Ghi chú:</td>
                            <td>
                                <asp:TextBox ID="txtNote" runat="server" TextMode="MultiLine" Rows="4"  CssClass="textbox textinfo textover" />
                            </td>
                        </tr>
                        <tr>
                            <td>Hình thức thanh toán:</td>
                            <td>
                                <select id="ddlPayment" runat="server" class="textbox textinfo" onchange="changePayment(this);" />
                            </td>
                        </tr>
                        <tr id="bank1">
                            <td>Số tài khoản:</td>
                            <td>
                                <asp:TextBox ID="txtBankNumber" runat="server" CssClass="textbox textinfo" />
                            </td>
                        </tr>
                        <tr id="bank2">
                            <td>Tên ngân hàng:</td>
                            <td>
                                <asp:TextBox ID="txtBankName" runat="server" CssClass="textbox textinfo" />
                            </td>
                        </tr>
                        <tr>
                            <td></td>
                            <td>                    
                                <div id="divError"></div>
                            </td>
                        </tr>
                        <tr>
                            <td></td>
                            <td>
                                <asp:Button ID="btnSave" runat="server" Text="Đặt hàng" CssClass="button" OnClientClick="return Valid();" />
                            </td>
                        </tr>
                    </table>
                </div>

                <div id="nocartDiv" runat="server">
                    Chưa có sản phẩm nào trong giỏ hàng<br />
                    <a href="/Index.aspx" title="Trở về trang chủ">Trở về trang chủ</a>
                </div>
                
                <div id="successDiv" runat="server" visible="false">
                    Đơn đặt hàng đã được gửi đi thành công. Chúng tôi sẽ sớm liên lạc với bạn.<br />
                    <a href="/Index.aspx" title="Trở về trang chủ">Trở về trang chủ</a>
                </div>

            </ContentTemplate>
        </asp:UpdatePanel>
    </div>
</asp:Content>
